<template>
  <div>
    <div class="detail-info" style="margin-top: 43px">
      <div class="form-item">
        <h4>基本信息</h4>
        <el-form label-width="180px">
          <el-row>
              <el-form-item label="分公司">
                <span>{{detailData.branchName}}</span>
              </el-form-item>
              <el-form-item label="所属部门">
                <span>{{detailData.departName}}</span>
              </el-form-item>
              <el-form-item label="客资类型">
                <span>{{detailData.customerName}}</span>
              </el-form-item>
              <el-form-item label="主广告语">
                <span>{{detailData.ad_words}}</span>
              </el-form-item>
              <el-form-item label="副广告语">
                <span>{{detailData.sub_ad_words}}</span>
              </el-form-item>
              <el-form-item label="广告图片">
                <img :src="imgHost + '/' + detailData.ad_pic" style="width:160px;height:100px;margin:5px 0" alt="">
              </el-form-item>
              <!--<el-form-item label="所属仓库">-->
                <!--<span>{{detailData.limitStoreName}}</span>-->
              <!--</el-form-item>-->
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="detail-info" style="margin-top: 43px">
      <div class="form-item">
        <h4>基本信息</h4>
        <el-form label-width="180px">
          <el-row>
              <el-form-item label="活动名称">
                <span>{{detailData.promotion_name}}</span>
              </el-form-item>
              <el-form-item label="副标题">
                <span>{{detailData.sub_promotion_name}}</span>
              </el-form-item>
              <el-form-item label="活动起止时间">
                <span>{{detailData.start_time}}</span> -
                <span>{{detailData.end_time}}</span>
              </el-form-item>
              <el-form-item label="满足条件">
                <span v-if="detailData.limit_mz_type === '1'">金额</span>
                <span v-if="detailData.limit_mz_type === '2'">数量</span>
              </el-form-item>
              <el-form-item label="活动类型">
                <span v-if="detailData.limit_type === '1'">阶梯</span>
                <span v-if="detailData.limit_type === '2'">每满</span>
              </el-form-item>
              <el-form-item v-if="detailData.limit_type === '1'">
                满 <span>{{detailData.limit_full_give[0].condition}}</span> <span v-if="detailData.limit_mz_type === '1'" >元</span><span v-else>件</span>,
                赠 <span>{{detailData.limit_full_give[0].gift[0].sku_id}}</span>&nbsp;&nbsp;
                数量 <span>{{detailData.limit_full_give[0].gift[0].num}}</span>&nbsp;&nbsp;
                赠品总数 <span>{{detailData.limit_full_give[0].gift[0].totalnum}}</span>&nbsp;&nbsp;
                促销费用 <span>{{detailData.limit_full_give[0].gift[0].promotionfeeid}}</span>&nbsp;&nbsp;
              </el-form-item>
              <el-form-item v-else>
                满 <span>{{detailData.limit_full_give[0].condition}}</span> <span v-if="detailData.limit_mz_type === '1'" >元</span><span v-else>件</span>,
                赠 <span>{{detailData.limit_full_give[0].gift[0].sku_id}}</span>&nbsp;&nbsp;
                数量 <span>{{detailData.limit_full_give[0].gift[0].num}}</span>&nbsp;&nbsp;
                赠品总数 <span>{{detailData.limit_full_give[0].gift[0].totalnum}}</span>&nbsp;&nbsp;
                促销费用 <span>{{detailData.limit_full_give[0].gift[0].promotionfeeid}}</span>&nbsp;&nbsp;
              </el-form-item>
              <!--<el-form-item v-if="detailData.limit_type === '1'" label="用户参与次数">-->
                <!--<span>{{detailData.limit_attend_count}}</span>-->
              <!--</el-form-item>-->
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="detail-info" style="margin-top: 43px">
      <div class="form-item">
        <h4>商品信息</h4>
        <el-table :data="detailData.main_product" border width="100%">
          <el-table-column prop="productid" label="商品ID" align="center" width="90"></el-table-column>
          <el-table-column prop="name" label="商品名称" align="center"></el-table-column>
          <el-table-column prop="saleunit" label="单位" align="center" width="100"></el-table-column>
          <el-table-column prop="salenorm" label="规格" align="center" width="100"></el-table-column>
          <el-table-column prop="saleprice" label="系统售价" align="center" width="100"></el-table-column>
          <!--<el-table-column-->
            <!--label="操作"-->
            <!--align="center"-->
            <!--width="100" >-->
            <!--<template scope="scope">-->
              <!--<el-button v-if="(status === 5 && scope.row.status === 1) || (status === 6 && scope.row.status === 1)" @click="offline(scope.$index, scope.row, $event)" size="small">下线</el-button>-->
              <!--<el-button v-else size="small">已下线</el-button>-->
            <!--</template>-->
          <!--</el-table-column>-->
        </el-table>
      </div>
    </div>
    <div class="detail-info" style="margin-top: 43px;margin-bottom:80px">
      <div class="form-item">
        <h4>审核信息</h4>
        <el-table :data="this.detailData.checkInfo" border>
          <el-table-column prop="auditor" label="审核人名称" align="center"></el-table-column>
          <el-table-column prop="content" label="任务内容" align="center"></el-table-column>
          <el-table-column prop="resultName" label="审核结果" align="center"></el-table-column>
          <el-table-column prop="opinion" label="审核意见" align="center"></el-table-column>
          <el-table-column prop="auditTime" label="审核时间" align="center"></el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>
<script>
  import { apiHost } from '../../../../../config/settings.js'
  import { activity } from '../../../../../config/proxy.js'
  export default {
    data () {
      return {
        detailData: [],
        status: '',
        data: '',
        feiyongList: []
      }
    },
    methods: {
      searchDetail (id) {
//        activity.cxfy.allList({type: 1, branchId: this.branchId, startTime: this.data.start_time, endTime: this.data.end_time}, (res) => {
//          if (res.message === 'ok') {
//            console.log(res.content)
//            this.feiyongList = res.content
//          }
//        }) // 获取促销费用
        activity.sphd.detail({id: id}, (res) => {
          console.log(res, '满赠详情')
          if (res.message === 'ok') {
            res.content.limit_full_give = JSON.parse(res.content.limit_full_give)
            res.content.limit_full_give.forEach((item, index) => {
              item.condition = Number(item.condition / 100).toFixed(2)
            })
            res.content.main_product.forEach((item, index) => {
              item.cgprice = Number(item.cgprice / 100).toFixed(2)
              item.saleprice = Number(item.saleprice / 100).toFixed(2)
            })
            this.detailData = res.content
          } else {
            this.message('查看详情失败', 'error')
          }
        })
      },
      timeDeltSecond (d) { // 时间去秒
        if (d) {
          return d.split(' ')[0]
        }
      },
      message (text, type) { // 消息提示
        this.$message({
          showClose: true,
          message: text,
          type: type
        })
      },
      offline (index, row, event) {
        activity.sphd.myj.manjian.offline({promotionId: this.data.promotion_id, productId: row.productid}, (res) => {
          if (res.message === 'ok') {
            this.detailData.main_product.splice(index, 1)
          } else {
            this.message('下线失败', 'error')
          }
        })
      } // 商品下线
    },
    created () {
      this.imgHost = apiHost.imgHost
      this.data = this.$store.state.tab.uid
      console.log(this.data)
      this.status = this.$store.state.tab.uid.status
      this.searchDetail(this.$store.state.tab.uid.id)
    },
    computed: {
      branchId: function (state) {
        return this.$store.state.user.info.branchId
      }
    }
  }
</script>

